package logic

import (
	"context"
	"local-life/models/mysql"

	"local-life/liferpc/internal/svc"
	"local-life/liferpc/liferpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type OrderAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewOrderAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *OrderAddLogic {
	return &OrderAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *OrderAddLogic) OrderAdd(in *liferpc.OrderAddRequest) (*liferpc.OrderAddResponse, error) {
	// todo: add your logic here and delete this line
	order := mysql.Orders{
		ShopId:     int(in.ShopId),
		OrdersItem: in.OrdersItem,
		OrdersNum:  int(in.OrdersNum),
	}
	mysql.DB.Debug().Create(&order)
	return &liferpc.OrderAddResponse{
		OrderId: int64(order.ID),
	}, nil
}
